<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - coverage.lcov - src/connectionhandling/mqtt_client_mqtt_connection_handler.dart</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">src/connectionhandling</a> - mqtt_client_mqtt_connection_handler.dart<span style="font-size: 80%;"> (source / <a href="mqtt_client_mqtt_connection_handler.dart.func.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">coverage.lcov</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">23</td>
            <td class="headerCovTableEntry">25</td>
            <td class="headerCovTableEntryHi">92.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2017-10-09</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntryHi">-</td>
          </tr>
          <tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : /*</a>
<span class="lineNum">       2 </span>            :  * Package : mqtt_client
<span class="lineNum">       3 </span>            :  * Author : S. Hamblett &lt;steve.hamblett@linux.com&gt;
<span class="lineNum">       4 </span>            :  * Date   : 22/06/2017
<span class="lineNum">       5 </span>            :  * Copyright :  S.Hamblett
<span class="lineNum">       6 </span>            :  */
<span class="lineNum">       7 </span>            : 
<span class="lineNum">       8 </span>            : part of mqtt_client;
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : ///  This class provides shared connection functionality to connection handler implementations.
<span class="lineNum">      11 </span>            : abstract class MqttConnectionHandler implements IMqttConnectionHandler {
<span class="lineNum">      12 </span>            :   dynamic connection;
<span class="lineNum">      13 </span>            : 
<span class="lineNum">      14 </span>            :   /// Registry of message processors
<span class="lineNum">      15 </span>            :   Map&lt;MqttMessageType, MessageCallbackFunction&gt; messageProcessorRegistry =
<span class="lineNum">      16 </span>            :   new Map&lt;MqttMessageType, MessageCallbackFunction&gt;();
<span class="lineNum">      17 </span>            : 
<span class="lineNum">      18 </span>            :   /// Registry of sent message callbacks
<span class="lineNum">      19 </span>            :   List&lt;MessageCallbackFunction&gt; sentMessageCallbacks =
<span class="lineNum">      20 </span>            :   new List&lt;MessageCallbackFunction&gt;();
<span class="lineNum">      21 </span>            : 
<span class="lineNum">      22 </span>            :   /// Connection state
<span class="lineNum">      23 </span>            :   ConnectionState connectionState = ConnectionState.disconnected;
<span class="lineNum">      24 </span>            : 
<span class="lineNum">      25 </span>            :   /// Use a websocket rather than TCP
<span class="lineNum">      26 </span>            :   bool useWebSocket = false;
<span class="lineNum">      27 </span>            : 
<span class="lineNum">      28 </span>            :   /// If set use a secure connection, note TCP only, not websocket.
<span class="lineNum">      29 </span>            :   bool secure = false;
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span>            :   /// Trusted certificate file path for use in secure working
<span class="lineNum">      32 </span>            :   String trustedCertPath;
<span class="lineNum">      33 </span>            : 
<span class="lineNum">      34 </span>            :   /// Private key file path
<span class="lineNum">      35 </span>            :   String privateKeyFilePath;
<span class="lineNum">      36 </span>            : 
<span class="lineNum">      37 </span>            :   /// Initializes a new instance of the MqttConnectionHandler class.
<span class="lineNum">      38 </span><span class="lineCov">          5 :   MqttConnectionHandler();</span>
<span class="lineNum">      39 </span>            : 
<span class="lineNum">      40 </span>            :   /// Connect to the specific Mqtt Connection.
<span class="lineNum">      41 </span>            :   Future connect(String server, int port, MqttConnectMessage message) async {
<span class="lineNum">      42 </span><span class="lineCov">          3 :     final Completer completer = new Completer();</span>
<span class="lineNum">      43 </span>            :     try {
<span class="lineNum">      44 </span><span class="lineCov">          6 :       await internalConnect(server, port, message);</span>
<span class="lineNum">      45 </span><span class="lineCov">          6 :       return completer.complete(this.connectionState);</span>
<span class="lineNum">      46 </span>            :     } catch (ConnectionException) {
<span class="lineNum">      47 </span><span class="lineCov">          1 :       this.connectionState = ConnectionState.faulted;</span>
<span class="lineNum">      48 </span>            :       rethrow;
<span class="lineNum">      49 </span>            :     }
<span class="lineNum">      50 </span><span class="lineCov">          1 :   }</span>
<span class="lineNum">      51 </span>            : 
<span class="lineNum">      52 </span>            :   /// Connect to the specific Mqtt Connection.
<span class="lineNum">      53 </span>            :   Future&lt;ConnectionState&gt; internalConnect(String hostname, int port,
<span class="lineNum">      54 </span>            :       MqttConnectMessage message);
<span class="lineNum">      55 </span>            : 
<span class="lineNum">      56 </span>            :   /// Sends a message to the broker through the current connection.
<span class="lineNum">      57 </span>            :   void sendMessage(MqttMessage message) {
<span class="lineNum">      58 </span><span class="lineCov">          6 :     MqttLogger.log(&quot;MqttConnectionHandler::sendMessage - $message&quot;);</span>
<span class="lineNum">      59 </span><span class="lineCov">          6 :     if ((connectionState == ConnectionState.connected) ||</span>
<span class="lineNum">      60 </span><span class="lineCov">          6 :         (connectionState == ConnectionState.connecting)) {</span>
<span class="lineNum">      61 </span><span class="lineCov">          3 :       final typed.Uint8Buffer buff = new typed.Uint8Buffer();</span>
<span class="lineNum">      62 </span><span class="lineCov">          3 :       final MqttByteBuffer stream = new MqttByteBuffer(buff);</span>
<span class="lineNum">      63 </span><span class="lineCov">          3 :       message.writeTo(stream);</span>
<span class="lineNum">      64 </span><span class="lineCov">          3 :       stream.seek(0);</span>
<span class="lineNum">      65 </span><span class="lineCov">          6 :       connection.send(stream);</span>
<span class="lineNum">      66 </span>            :       // Let any registered people know we're doing a message.
<span class="lineNum">      67 </span><span class="lineCov">          6 :       for (MessageCallbackFunction callback in sentMessageCallbacks) {</span>
<span class="lineNum">      68 </span><span class="lineCov">          3 :         callback(message);</span>
<span class="lineNum">      69 </span>            :       }
<span class="lineNum">      70 </span>            :     } else {
<span class="lineNum">      71 </span><span class="lineCov">          3 :       MqttLogger.log(&quot;MqttConnectionHandler::sendMessage - not connected&quot;);</span>
<span class="lineNum">      72 </span>            :     }
<span class="lineNum">      73 </span>            :   }
<span class="lineNum">      74 </span>            : 
<span class="lineNum">      75 </span>            :   /// Runs the disconnection process to stop communicating with a message broker.
<span class="lineNum">      76 </span>            :   ConnectionState disconnect();
<span class="lineNum">      77 </span>            : 
<span class="lineNum">      78 </span>            :   /// Closes the connection to the Mqtt message broker.
<span class="lineNum">      79 </span>            :   void close() {
<span class="lineNum">      80 </span><span class="lineCov">          4 :     if (connectionState == ConnectionState.connected) {</span>
<span class="lineNum">      81 </span><span class="lineCov">          2 :       disconnect();</span>
<span class="lineNum">      82 </span>            :     }
<span class="lineNum">      83 </span>            :   }
<span class="lineNum">      84 </span>            : 
<span class="lineNum">      85 </span>            :   /// Registers for the receipt of messages when they arrive.
<span class="lineNum">      86 </span>            :   void registerForMessage(MqttMessageType msgType,
<span class="lineNum">      87 </span>            :       MessageCallbackFunction callback) {
<span class="lineNum">      88 </span><span class="lineCov">         10 :     messageProcessorRegistry[msgType] = callback;</span>
<span class="lineNum">      89 </span>            :   }
<span class="lineNum">      90 </span>            : 
<span class="lineNum">      91 </span>            :   /// UnRegisters for the receipt of messages when they arrive.
<span class="lineNum">      92 </span>            :   void unRegisterForMessage(MqttMessageType msgType) {
<span class="lineNum">      93 </span><span class="lineNoCov">          0 :     messageProcessorRegistry.remove(msgType);</span>
<span class="lineNum">      94 </span>            :   }
<span class="lineNum">      95 </span>            : 
<span class="lineNum">      96 </span>            :   /// Registers a callback to be called whenever a message is sent.
<span class="lineNum">      97 </span>            :   void registerForAllSentMessages(MessageCallbackFunction sentMsgCallback) {
<span class="lineNum">      98 </span><span class="lineCov">          6 :     sentMessageCallbacks.add(sentMsgCallback);</span>
<span class="lineNum">      99 </span>            :   }
<span class="lineNum">     100 </span>            : 
<span class="lineNum">     101 </span>            :   /// UnRegisters a callback that is called whenever a message is sent.
<span class="lineNum">     102 </span>            :   void unRegisterForAllSentMessages(MessageCallbackFunction sentMsgCallback) {
<span class="lineNum">     103 </span><span class="lineNoCov">          0 :     sentMessageCallbacks.remove(sentMsgCallback);</span>
<span class="lineNum">     104 </span>            :   }
<span class="lineNum">     105 </span>            : 
<span class="lineNum">     106 </span>            :   /// Handles the Message Available event of the connection control for handling non connection messages
<span class="lineNum">     107 </span>            :   void messageAvailable(events.Event&lt;MessageAvailable&gt; event) {
<span class="lineNum">     108 </span>            :     final MessageCallbackFunction callback =
<span class="lineNum">     109 </span><span class="lineCov">         18 :     messageProcessorRegistry[event.data.message.header.messageType];</span>
<span class="lineNum">     110 </span><span class="lineCov">          9 :     callback(event.data.message);</span>
<span class="lineNum">     111 </span>            :   }
<span class="lineNum">     112 </span>            : }
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.10</a></td></tr>
  </table>
  <br>

</body>
</html>
